<tagLib name="html" />
<include file="Public:header" />
<load href ="__PUBLIC__/Js/common.js" />
<div id="main" class="main" >
<script language="JavaScript">
<!--
function getProductPrice(){
	var pid = $('productId')[$('productId').selectedIndex].value;
    var productName = $('productId')[$('productId').selectedIndex].text;
    $('productName').value = productName;
    ThinkAjax.send('__APP__/Product/getPrice/','pid='+pid,insertPrice,'','');
}
function insertPrice(json){
	$('price').value=json.price;
	if(json.isExt==1){
		if($('extMoney')>0){
			$('isExt').selectedIndex = json.isExt;
			$('info').style.display='inline';
		}else{
		}
	}else{
		$('info').style.display='none';
	}

	$('useTimes').value=json.times;
}


function setSalerName(){
	$('salerName').value = $('salerId')[$('salerId').selectedIndex].innerText;
}

function checkExt(){
	if($('extMoney').value==0){
		alert('该会员赠送帐户余额为0,不可使用优惠!');
		$('isExt').selectedIndex = 0;
		return false;
	}
}

function checkInfo(){
	if($('productId').value==0){
		alert('请选择要购买的产品!');
		return false;
	}
	if($('salerId').value==0){
		alert('请选择销售顾问!');
		return false;
	}
	var enough;
	if($('isExt').value==1){
		var money = $('price').value;    // 价格
		var ext   = $('extMoney').value; // 优惠金额
		enough = $('money').value + $('extMoney').value; - $('price').value;
		if(enough<0){
			alert('会员卡余额不足,请先充值!');
			return false;
		}
 		var pay   = money-ext;    // 会员卡扣除金额

	}else{
		enough = $('money').value - $('price').value;
		if(enough<0){
			alert('会员卡余额不足,请先充值!');
			return false;
		}
	}
	return confirm("请确认购买产品\n将从会员卡中扣除金额：￥"+$('price').value);

}
//-->
</script>
<div class="content">
<div class="title">[<a href="#" onclick="history.back();">返回</a>]购买产品</div>
<table cellpadding=3 cellspacing=3>
<form method='post' id="form1" action="__APP__/Productlog/insert/" onsubmit="return checkInfo();" method="get">
<input type="hidden" name="productName" id="productName"/>
<tr>
	<td class="tRight">产品:</td>
	<td class="tleft" >
					<SELECT class="medium bLeft"  name="productId" id="productId" onchange="getProductPrice();">
							<option value="0">请选择产品</option>
							<volist name="products" id="pt">
								<option value="{$pt.id}">{$pt.name}</option>
							</volist>
					</SELECT>
	</td>
</tr>
<tr>
	<td class="tRight">价格:</td>
	<td><input type="text" class="red" name="price" id="price" value="0" readonly></td>
</tr>
<tr>
	<td class="tRight">可用次数:</td>
	<td><input type="text"  class="red" name="useTimes" id="useTimes" value="0" readonly /></td>
</tr>
<tr>
	<td class="tRight">是否优惠:</td>
	<td>
		<SELECT class="medium bLeft"  name="isExt" id="isExt" onchange="checkExt();">
			<option value="0">否</option>
			<option value="1">是</option>
		</SELECT><span id="info" style="display:none" class="green">可用赠送金额结算</span>
	</td>
</tr>
<tr>
	<td class="tRight">销售顾问:</td>
	<td class="tleft" >
				<SELECT class="medium bLeft"  name="salerId" id="salerId">
						<option value="0">请选择销售顾问</option>
						<volist name="salers" id="saler">
							<option value="{$saler.id}">{$saler.nickname}</option>
						</volist>
				</SELECT>
	</td>
</tr>
<tr>
	<td class="tRight">会员卡余额:</td>
	<td class="tleft"><input name="money" id="money" value="{$card.money}" /></td>
</tr>
<tr>
	<td class="tRight">赠送余额:</td>
	<td class="tleft"><input id="extMoney" name="extMoney" value="{$card.extMoney}" /></td>
</tr>
<tr>
	<td class="tRight tTop">操作人：</td>
	<td class="tLeft" >{$Think.session.loginUserName}</td>
</tr>
<input type="hidden" name="cardId" value="{$card.id}" />
<input type="hidden" name="money" value="{$card.money}" />
<input type="hidden" id="extMoney" name="extMoney" value="{$card.extMoney}" />
<input type="hidden" name="memberId" value="{$card.memberId}" />
<input type="hidden" name="operatorId" value="{$Think.session.myauthId}" />

<tr>
	<td></td>
	<td class="center">
	<input type="submit" value="购 买" class="small submit" />
	<input type="reset" class="submit  small" value="清 空" >
	</td>
</tr>
</table>
</form>
</div>
</div>
